package com.spring.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")

public class TestController {

    // GET请求和POST请求都支持（默认八种请求都支持）
    @RequestMapping("/hello1")
    public String hello1(){
        return "test world1";
    }

    // 仅支持GET请求（传参）
    // 参数可以传多个，表示这一组请求类型都支持
    // @RequestMapping(value = "/hello2", method = {RequestMethod.GET,RequestMethod.POST})
    @RequestMapping(value = "/hello2", method = RequestMethod.GET)
    public String hello2(){
        return "test world2";
    }

    // 仅支持POST请求
    @RequestMapping(value = "/hello3", method = RequestMethod.POST)
    public String hello3(){
        return "test world3";
    }

    // 仅支持GET请求（注解）和 @RequestMapping加参数等价
    @GetMapping("/hello4")
    public String hello4(){
        return "test world4";
    }

    // 仅支持POST请求
    @GetMapping("/hello5")
    public String hello5(){
        return "test world5";
    }
}
